﻿@model IList<FCDB.Entity.FormCirculatedDocumentLog>
@using FCDB.Web.Helpers;

<table>
@if (Model.Count(t => t.UserID == ViewBag.FormUserID&& t.CheckType == 2 && t.Status == 0) > 0)
{
    FCDB.Entity.FormCirculatedDocumentLog item = Model.First(t => t.UserID == ViewBag.FormUserID && t.CheckType == 2 && t.Status == 0);
    string str = item.CreateUserName + item.CreateTime.Value.ToString(AppSettings.DefaultDateTimeFormat);
    var question = item.Question;
    <tr id="trFormCirculatedDocumentLog">
        <td>
            @*
            通知发起人：
            <input id="cbLogEmail" type="checkbox" />邮件
            <input id="cbLogMessage" type="checkbox" />短信 <br />*@
            
            <div>
            征求的问题 ︰ @question
            </div>
            @str
        </td>
    </tr> 
    <tr>
        <td>
            <input  type="hidden"  id="hFormCirculatedDocumentLog"  value='@item.ID' />
            <textarea id="txtLogContent"   name="Content" cols="20" rows="2" style="width:98%; height:100px;"></textarea>
        </td>
    </tr>
}
@if (Model.Count(t => t.UserID == ViewBag.FormUserID && t.CheckType == 1 && t.Status == 0) > 0)
{
    FCDB.Entity.FormCirculatedDocumentLog item = Model.First(t => t.UserID == ViewBag.FormUserID && t.CheckType == 1 && t.Status == 0);
        <tr id="trViewForm">
            <td>
                  <input  type="hidden" id="hFormCirculatedDocumentLog"  value='@item.ID' />
            </td>
        </tr> 
}
@if (Model != null && Model.Count > 0)
{     
    IList<FCDB.Entity.FormCirculatedDocumentLog> logList=Model.OrderBy(t=>t.UpdateTime).ToList();
    for (int index = 0; index < logList.Count; )
    {
        FCDB.Entity.FormCirculatedDocumentLog item = logList[index]; 
        if (item.CheckType == 1)
        {
            IList<FCDB.Entity.FormCirculatedDocumentLog> list = logList.Where(t => t.CreateUserID == item.CreateUserID&&t.CheckType==1).ToList();
            foreach (var logItem in list)
            {
                logList.Remove(logItem);
            }
            if (list.Count == 0)
            {
                index++;
            }
            string CreateUserName = item.CreateUserName;
            string createTime = item.CreateTime.Value.ToString(AppSettings.DefaultDateTimeFormat); 
            <tr>
                <td>
                      <div style="padding: 2px 0 2px 0;">
                    <b>@CreateUserName</b> (@createTime)传阅：  
                    @foreach(var logItem in list)
                    { 
                        <div style="margin-left:8px;">
                            <b> @logItem.UserName</b>
                            <span>(</span>
                            @(logItem.UpdateTime.HasValue?logItem.UpdateTime.Value.ToString(AppSettings.DefaultDateTimeFormat):"")
                            <span>)</span>  
                            <p>
                            <span>@logItem.Content</span>
                            </p>
                        </div>
                    }
                   </div>
                </td>
            </tr>
            
          
        }
        else
        {
            IList<FCDB.Entity.FormCirculatedDocumentLog> list = logList.Where(t => t.Question == item.Question&&t.CheckType==2).ToList();
            foreach (var logItem in list)
            {
                logList.Remove(logItem); 
            }
            if (list.Count == 0)
            {
                index++;
            }
            string CreateUserName = item.CreateUserName;
            string createTime = item.CreateTime.Value.ToString(AppSettings.DefaultDateTimeFormat);
            string question = item.Question; 
             <tr>
                <td>
                    <div style="padding: 2px 0 2px 0;">
                    <b>@CreateUserName</b> (@createTime)征求的问题 ： 
                    <p> @question </p> 
                    @foreach(var logItem in list)
                    { 
                        <div style="margin-left:8px;">
                            <b> @logItem.UserName</b>
                            <span>(</span>
                            @(logItem.UpdateTime.HasValue?logItem.UpdateTime.Value.ToString(AppSettings.DefaultDateTimeFormat):"")
                            <span>)</span> 
                            的意见 ：
                            <p>
                            <span>@logItem.Content</span>
                            </p>
                        </div>
                    }
                   </div>
                </td>
            </tr>
            
        }
    }  
}
</table>

<script type="text/javascript"  > 
    function ViewForm() {
        var id = $("#hFormCirculatedDocumentLog").val();
        var url = '@Url.Action("SaveFormCirculatedDocumentLog","Form")';
        var content = $("#txtLogContent").val();
        $.post(url,{id:id,content:content},function(data)
        {
            winClose(1);
        });
    }
    function SendDocumentLogwForm() {
        var id = $("#hFormCirculatedDocumentLog").val();
        var url = '@Url.Action("SaveFormCirculatedDocumentLog","Form")'; 
        var content = $("#txtLogContent").val();
        $.post(url, { id: id, content: content }, function (data) {
            winClose(1);
        });
    }
    $(function () {
        if ($("#trFormCirculatedDocumentLog").length == 0) {
            $("#btnSendDocumentLogwForm").remove();
        }
        if ($("#trViewForm").length == 0) {
            $("#btnViewForm").remove();
        }
    });
</script>